package txunda.com.decoratemaster.tools;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.v4.content.FileProvider;
import android.support.v7.app.AppCompatActivity;

import java.io.File;

import txunda.com.decorate.BuildConfig;

/**
 * @author Taurus
 * @Description 我的工具
 * @created at 2017/12/8 14:03
 * @E-mail TaurusAndroid@163.com
 */

public class MyTools implements Config {
//    // 请求头像图片
//    public static void getCirclePic(Context context, String url, final ImageView iv, int resourceID) {
//        Glide.with(context).load(url).
//                placeholder(resourceID).
//                error(resourceID).
//                transform(new GlideCircleTransform(context)).
//                into(new SimpleTarget<GlideDrawable>() {
//                    @Override
//                    public void onResourceReady(GlideDrawable resource,
//                                                GlideAnimation<? super GlideDrawable> glideAnimation) {
//                        iv.setImageDrawable(resource);
//                    }
//                });
//    }

    public static Uri file2Uri(Context ctx, File file) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            return FileProvider.getUriForFile(ctx, BuildConfig.APPLICATION_ID + ".FileProvider", file);
        } else {
            return Uri.fromFile(file);
        }
    }
    // 广播更新相册
    public static void updateAlbum(Context context, File file){
        Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
        Uri uri = Uri.fromFile(file);
        intent.setData(uri);
        context.sendBroadcast(intent);
    }
    public static void startPhotoZoom(Uri uri, Uri imageUri, Context context) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

        intent.putExtra("scale", true);// 去黑边
        intent.putExtra("scaleUpIfNeeded", true);// 去黑边
        intent.putExtra("OvalDimmedLayer", false);// 去黑边
        // outputX outputY 是裁剪图片宽高
        intent.putExtra("aspectX", 150);
        intent.putExtra("aspectY", 150);
        intent.putExtra("outputX", 150);
        intent.putExtra("outputY", 150);
        intent.putExtra("return-data", false);
        intent.putExtra("noFaceDetection", true);
        intent.putExtra("outputFormat", Bitmap.CompressFormat.JPEG.toString()); // 输出的图片格式
        intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
        ((AppCompatActivity) context).startActivityForResult(intent, PHOTO_RESOULT);
    }
}
